class Animal2{
    private String name;
    private int age;

    public Animal2(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name+"吃食物");
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}
class Cat extends Animal2{

    public Cat(String name, int age) {
        super(name, age);
    }

    public void eat(){
        System.out.println(super.getAge() + "岁的" + super.getName() + "吃猫粮");
    }
}
class Dog1 extends Animal2{
    public Dog1(String name, int age) {
        super(name, age);
    }
    public void eat(){
        System.out.println(super.getAge() + "岁的" + super.getName() + "吃狗粮");
    }
}


public class Test3 {
    public  static void punc(Animal2 animal){//向上转型
        animal.eat();
    }

    public static void main(String[] args) {
       Dog1 d = new Dog1("大飞",4);
       Cat c = new Cat("白糖",3);
       punc(d);
       punc(c);
    }
}
